package interviewClassic150;

import org.junit.Test;

public class MajorityElement {
    public int majorityElement(int[] nums) {
        int n = nums.length;
        int res = nums[0];
        int vote = 1;

        for (int i = 1; i < n; i++) {
            int num = nums[i];
            if (vote == 0) res = num;
            vote += res == num ? 1 : -1;
        }

        return res;
    }

    @Test
    public void test() {
        int[] nums = {6,5,5};
        int i = majorityElement(nums);
        System.out.println(i);
    }
}
